home *** CD-ROM | disk | FTP | other *** search
/ Archive Magazine CD 1995 / Archive Magazine CD 1995.iso / discs / shareware / share_41 / assembler / examples / sum2 < prev    next >
Text File  |  1991-05-15  |  846b  |  27 lines

  1. ; NAME       sum
  2. ; PURPOSE    sums the numbers 0 to number1
  3. ; DESIGN  
  4. ;            result <- 0
  5. ;            load number1
  6. ;            for  number1 <- number1 downto 0
  7. ;              add number1 to result
  8. ;            end for
  9. ;            store result in number3
  10. ; NOTE
  11. ;            this differs from sum by setting the zero flag in the subtraction
  12. ;            this avoids one instruction
  13. ;            sum to 50000 is maximum without overflow
  14. ;            on arm 2 this takes 0.057 seconds
  15.  
  16.  
  17.  
  18.  
  19. ldr r7, [r1]            ; load number 1 to r7
  20. mov r8, #0              ; set result r8 to zero
  21. .loop     
  22.   add r8, r8, r7        ; add number to result
  23.   subs r7, r7, #1       ; decrement the number and set the flags
  24. bge loop                ; branch if its greater than zero back round the loop
  25. str r8, [r3]            ; store the result in number 3
  26.  
  27.